Skip to content

helper functions for Filesystem error handling #1015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

wassup05
Copy link
Contributor

@wassup05 wassup05 commented Jul 12, 2025

Functions added are:

  • fs_error: just sets the flag of state_type to STDLIB_FS_ERROR and passes the remaining 20 arguments to it
  • fs_error_code: sets the flag as above and also prefixes the code (integer argument) accordingly.

I tried using an interface block to handle both of these together, but that introduces ambiguity for the compiler.

Could make code an optional argument and depending on if it's present or not pass 18 or 20 arguments to state_type but I feel that the 2 unused arguments in that case would not be correct.

Inspired from @perazz in #1006 (comment)

@jalvesz
Copy link
Contributor

jalvesz commented Jul 16, 2025

Thanks for this PR @wassup05. Question: is there a reason for using UPPER_CASE ? The style guide promotes snake_case for procedures and constants.

@wassup05
Copy link
Contributor Author

Oh no, It was just because it was an error and I felt it was better to emphasize that, but I'll change it

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces two helper functions fs_error and fs_error_code to simplify filesystem error handling in the stdlib_system module. These functions provide convenient ways to create state_type objects with the STDLIB_FS_ERROR flag set.

  • Adds fs_error function that accepts up to 20 optional arguments and creates a filesystem error state
  • Adds fs_error_code function that prefixes an error code to the message and accepts up to 19 additional arguments
  • Includes comprehensive tests, documentation, and example code

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/stdlib_system.F90 Implements the two new helper functions and adds required imports
test/system/test_filesystem.f90 Adds unit tests for both helper functions
doc/specs/stdlib_system.md Documents the new functions with detailed specifications
example/system/example_fs_error.f90 Provides usage examples for both functions
example/system/CMakeLists.txt Registers the new example in the build system
Comments suppressed due to low confidence (2)

test/system/test_filesystem.f90:25

  • The subroutine name test_fs_error is inconsistent with the test name test_FS_ERROR used in new_unittest. Consider renaming to test_FS_ERROR for consistency.
    subroutine test_fs_error(error)

doc/specs/stdlib_system.md:472

  • The syntax example shows fs_error but should be fs_error_code since this is documenting the fs_error_code function.
`err = fs_error(code [, a1,a2,a3,a4...... a19])`

Comment on lines 788 to 803
pure function fs_error_code(code,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10, &
a11,a12,a13,a14,a15,a16,a17,a18, a19) result(state)

type(state_type) :: state
!> Platform specific error code
integer, intent(in) :: code
!> Optional rank-agnostic arguments
class(*), intent(in), optional, dimension(..) :: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10, &
a11,a12,a13,a14,a15,a16,a17,a18, a19

character(32) :: code_msg

write(code_msg, "('code - ', i0, ',')") code

state = state_type(STDLIB_FS_ERROR, code_msg,a1,a2,a3,a4,a5,a6,a7,a8, &
a9,a10,a11,a12,a13,a14,a15,a16,a17,a18, a19)
Copy link
Preview

Copilot AI Jul 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The function signature spans multiple lines but lacks consistent spacing after commas. Consider adding spaces after commas for better readability: code, a1, a2, a3, ...

Suggested change
pure function fs_error_code(code,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10, &
a11,a12,a13,a14,a15,a16,a17,a18, a19) result(state)
type(state_type) :: state
!> Platform specific error code
integer, intent(in) :: code
!> Optional rank-agnostic arguments
class(*), intent(in), optional, dimension(..) :: a1,a2,a3,a4,a5,a6,a7,a8,a9,a10, &
a11,a12,a13,a14,a15,a16,a17,a18, a19
character(32) :: code_msg
write(code_msg, "('code - ', i0, ',')") code
state = state_type(STDLIB_FS_ERROR, code_msg,a1,a2,a3,a4,a5,a6,a7,a8, &
a9,a10,a11,a12,a13,a14,a15,a16,a17,a18, a19)
pure function fs_error_code(code, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, &
a11, a12, a13, a14, a15, a16, a17, a18, a19) result(state)
type(state_type) :: state
!> Platform specific error code
integer, intent(in) :: code
!> Optional rank-agnostic arguments
class(*), intent(in), optional, dimension(..) :: a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, &
a11, a12, a13, a14, a15, a16, a17, a18, a19
character(32) :: code_msg
write(code_msg, "('code - ', i0, ',')") code
state = state_type(STDLIB_FS_ERROR, code_msg, a1, a2, a3, a4, a5, a6, a7, a8, &
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19)

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@jalvesz jalvesz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @wassup05 LGTM

@perazz perazz changed the title helper functions for Fileysystem error handling helper functions for Filesystem error handling Jul 19, 2025
Copy link
Member

@perazz perazz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR @wassup05. I added a few comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants